<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>对象属性简写</h1>
    <ul>
        <li>如果对象的属性名和变量名一致，可以简写。</li>
        <li>方法的简写</li>
    </ul>
    <script>
        let name = "奉先";
        let age = 35;

        let obj = {
            name: name,
            age: age,
        }

        // ES6时，如果属性名和属性值一致，那么可以简写
        function createObject(name,age) {
            return {name,age};
        }
        let obj2 = createObject("罗佰君",20);
        console.log(obj2);

        let obj3 = {
            showName: function() {
                console.log("奉先");
            }
        }

        // ES6简写：
        let obj4 = {
            sayHello(name) {
                console.log("Hello:",name);
            }
        }
        obj4.sayHello("胡正");

        let obj5 = {
            sayHello: function(name) {
                console.log("Hello:",name);
            },
            doWork(name) {
                console.log("快去工作:",name);
            },
            eat: name => {
                console.log("快去吃饭:",name);
            }
        }



    </script>


</body>
</html>